package nineteenthDay;

import java.util.ArrayList;
import java.util.List;

public class FindTarget {
    List<Integer> ans = new ArrayList<>();
    public boolean findTarget(TreeNode root, int k) {
        inorder(root);
        int left = 0, right = ans.size()-1;
        while (left < right){
            if (ans.get(left) + ans.get(right) > k){
                right--;
            } else if (ans.get(left) + ans.get(right) < k) {
                left++;
            } else {
                return true;
            }
        }
        return false;
    }
    public void inorder(TreeNode node) {
        if (node == null){
            return;
        }
        inorder(node.left);
        ans.add(node.val);
        inorder(node.right);
    }
}
